Extreme PALS Game Framework

Implementing your first features

You are at the stage, where everyone in the team has the game on their computers and can run it successfully. What happens now?

If you have some ideas - feel free to explore them yourself! But you may want to first read through the next section about how to work on the project together with your teammates ;)

Sharing is caring - sharing your changes with your team

How to actually make changes to the project will be covered later in this one and in other guides. But once you have made something - anything at all, it could simply be an added comment with your name for a start, you will need a way to share your changes with the rest of your team.

Photo of a cute dog, who thought sharing was caring

This is where all the hassle with Git and GitHub really pays off.

Open up a terminal window and navigate to your project folder. Then type git add --all to stage all changes (again, for discussion about what this means, refer to the other guidebooks mentioned in the Getting Set Up guide).

Then type git status to check that everything you wanted to change shows up.

One more command - type git commit -m "Your Message" replacing the words Your Message with a very short description of what your changes were about.

And finally, type git push. If git tells you:

fatal: The current branch SuperCoolFeature has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin SuperCoolFeature

Then try the command it suggests. At this point Git will most likely ask you for your GitHub username and password, after which, it will do its magic and your changes will be up online.

The rest of your teammates will have to run git pull to get those changes on their computers.

You can switch between each others’ branches by typing git checkout SomeCoolBranchName.

To merge the changes together, you will have to make a pull request from your branch to the master branch. You can find instructions for how to do so here

A good starting point - where to begin if you’re unsure

Why not try out the game first! When run, it should look something like this:

Walking without animation

You will notice that the game has very little in it. You can move about, but there a block blocking the path forward and there is no way to jump. And even the little it has, is quite buggy - when you press left, the character moves right and vice versa!

Fixing this is a good starting point.

The relevant part we will want to focus on is in the key handling function. This is the part of code that is responsible for connecting the keys the user presses to actions in the game.

Let’s open up the GameManager.java file and scroll all the way down to the manageKeys function.

In it, see if you can find those naughty lines responsible for the mixed up movement!

Hint: you are looking for these ~

// If right arrow is pressed - move the boy right
if (currentKeys.contains(KeyEvent.VK_RIGHT)){
    boy.moveLeft(isLastLevel());
}

// If left arrow is pressed - move the boy left
if (currentKeys.contains(KeyEvent.VK_LEFT)){
    boy.moveRight(isLastLevel());
}

Swapping them is simple - just exchange the contents of the if-statement blocks, so that it looks like this:

// If right arrow is pressed - move the boy right
if (currentKeys.contains(KeyEvent.VK_RIGHT)){
    boy.moveRight(isLastLevel());
}

// If left arrow is pressed - move the boy left
if (currentKeys.contains(KeyEvent.VK_LEFT)){
    boy.moveLeft(isLastLevel());
}

After saving your changes, try running the game now. Has the movement been fixed? If so - awesome! \(^.^)/

Now you can track changes with Git using git add YourProjectName/YourPath and commit them with git commit -m "some descriptive message". Finally, run git push and everyone on the team will be able to see the changes online.

Note that if multiple teammates were on the same branch - you will get a merge conflict. This is why it is best for everyone to work on different branches at first. If it happens - do not worry, just ask one of the demonstrators to help out ( ͡° ͜ʖ ͡°)ノ=☆

Make the world bouncy! - implementing jumping in the game

It’s time to get past that bully path-blocking block. Let’s implement jumping in the game!

What function will you need to look at? Hint: we have already seen this function when fixing character movement.

It’s the manageKeys function. In it, you can find the lines saying:

// If jump key is pressed - make the boy jump
// TODO: implement me!

Choose a key that you would like to make the character jump. Thinking vanilla, you could choose spacebar - but you could also make it something weird like TAB ¯\_(° ͜ʖ °)_/¯ When you have decided, you will need to call boy.startJumping() when that key is pressed.

The actual functionality of jumping is already implemented in Boy.java, so there’s no need to write your own behaviour just yet. If you wanted to add jumping with spacebar, the end result would look like this:

// If spacebar is pressed - make the boy jump
if (currentKeys.contains(KeyEvent.VK_SPACE)) {
    boy.startJumping();
}

Now try running the game. It should be possible to finally jump.

Here is a screenshot of the character, having conquered the path-blocking block!

Jumping in the game

Next steps

Alright! You’ve gotten some basic functionality working in the game. That is - until you notice that jumping is incredibly broken, because the character does not actually fall. But that is the topic of the next tutorial guide.

See you there!

Portal to the next guide